<template>
    <div class="lists" ref="list">
        <div>
            <div class="list">
                <div class="title border-topbottom">当前城市</div>
                <div class="city-item">
                    <div class="button-list">
                        <div class="button">
                            {{this.city}}
                        </div>
                    </div>
                </div>
            </div>
            <div class="list">
                <div class="title border-topbottom">热门城市</div>
                <div class="city-item">
                    <div
                        class="button-list"
                        v-for="list of hot"
                        :key="list.id"
                        @click="changeCitya(list.name)"
                    >
                        <div class="button">{{list.name}}</div>
                    </div>
                </div>
            </div>
            <div
                class="list"
                v-for="(list, key) of cities"
                :key="key"
                :ref="key"
            >
                <div class="title border-topbottom">{{key}}</div>
                <div
                    class="city-item"
                    v-for="item of list"
                    :key="item.id"
                    @click="changeCitya(item.name)"
                >
                    <div class="item-list border-bottom">{{item.name}}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
/* eslint-disable */
import BScroll from 'better-scroll'
import { mapState, mapMutations } from 'vuex'
export default {
    name: 'cityList',
    props: {
        hot : Array,
        cities : Object,
        letter: String
    },
    computed: {
        ...mapState({
            city: 'city'
        })
    },
    methods: {
        changeCitya(city) {
            this.changeCity(city)
            this.$router.push('/')
        },
        ...mapMutations(['changeCity'])
    },
    mounted() {
        this.scroll = new BScroll(this.$refs.list)
    },
    watch: {
        letter(){
            if(this.letter){
                const element = this.$refs[this.letter][0]
                this.scroll.scrollToElement(element)
            }
        }
    }
}
</script>

<style lang="stylus" scoped>
    .border-topbottom
        &:before
            border-color #ccc
        &:after
            border-color #ccc
    .border-bottom
        &:before
            border-color #ccc
    .lists
        position absolute
        overflow hidden
        top 1.62rem
        left 0
        bottom 0
        right 0
        .title
            height .64rem
            line-height .64rem
            text-align left 
            padding-left .2rem
            background #eee
            color #666
        .city-item
            overflow hidden
            padding .1rem .6rem .1rem .1rem
            .button-list
                float left
                width 33.33%
                .button
                    margin .1rem
                    padding .1rem 0
                    color #666
                    border .02rem solid #ccc
                    text-align center
                    border-radius .06rem
        .city-item
            padding-left .2rem
            .item-list
                text-align left 
                height .64rem
                line-height .64rem
</style>
